/*
 * ChildBrowser.cpp
 *
 *  Created on: 2011. 4. 14.
 *      Author: JeeHoon
 */
#include <FApp.h>
#include "plugin/ChildBrowser.h"
#include "api/PluginManager.h"
#include "api/PluginResult.h"
#include "ChildPhoneGapForm.h"

using namespace Osp::Base;

ChildBrowser::ChildBrowser()
{
}

ChildBrowser::~ChildBrowser()
{
}

result
ChildBrowser::OnConstruct(PluginManager * pPluginManager, Osp::Base::String pluginName)
{
	result r = E_SUCCESS;

	return r;
}

result
ChildBrowser::execute(Osp::Base::String action, Osp::Base::String args, Osp::Base::String callbackId)
{
	result r = E_SUCCESS;

	if(action == L"showWebPage")
	{
		String url = URLDecode(callbackId);
		Osp::Base::Collection::ArrayList * pArgs = new Osp::Base::Collection::ArrayList();
		pArgs->Construct();
		pArgs->Add(* new ChildPhoneGapForm(this));
		pArgs->Add(* new String(url));

		Osp::App::Application::GetInstance()->SendUserEvent(EVENT_CHILD_PHONEGAP_OPEN,pArgs);
	}
	else if(action == L"close")
	{
		Osp::App::Application::GetInstance()->SendUserEvent(EVENT_CHILD_PHONEGAP_CLOSE,NULL);
	}
	else
	{
		printLog(L"Unknown action: " + action );
	}

	return r;
}

void
ChildBrowser::OnLocationChange(Osp::Base::String url)
{
	__pPluginManager->evaluateJavascript(L"ChildBrowser._onLocationChange('"+ url +L"');");
}

void
ChildBrowser::OnClose()
{
	__pPluginManager->evaluateJavascript(L"ChildBrowser._onClose();");
}

void
ChildBrowser::OnOpenExternal()
{
	__pPluginManager->evaluateJavascript(L"ChildBrowser._onOpenExternal();");
}


